#include <workflow/WFTaskFactory.h>
#include <workflow/RedisMessage.h>
#include <workflow/WFFacilities.h>
#include <iostream>
#include <signal.h>

WFFacilities::WaitGroup wait_group(1);
std::string url = "*";

void redis_dfs_callback(WFRedisTask *task) {
    protocol::RedisResponse *resp = task->get_resp();
    int state = task->get_state();
    int error = task->get_error();

    if (state == WFT_STATE_SUCCESS) {
        protocol::RedisValue val;
        resp->get_result(val);
        if (val.is_string()) {
//################################ DFS部分 ##################################
            if(val.string_value() == "100"){
                printf("find the 100\n");
                wait_group.done();
            }else{
                WFRedisTask *dfs_task = WFTaskFactory::create_redis_task(url, 3, redis_dfs_callback);
                dfs_task->get_req()->set_request("get", {val.string_value()});
                series_of(task)->push_back(dfs_task);
            }
//##########################################################################
        } else {
            std::cout << "Unexpected response type." << std::endl;
        }
    } else {
        std::cerr << "Task error: state=" << state << " error=" << error << std::endl;
    }
}

int main() {


    WFRedisTask *task = WFTaskFactory::create_redis_task(url, 3, redis_dfs_callback);
    task->get_req()->set_request("get", {"x1"});

    task->start();
    wait_group.wait();

    return 0;
}
